﻿using AutoMapper;
using MediatR;
using SlaughterItem.Common.Domains.Setup;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week02.Setups
{
    /// <summary>
    /// 待宰圈设置删除
    /// </summary>
    public class WaitingDeleteHandler : IRequestHandler<WaitingDeleteCommand, Result>
    {
        private readonly IBaseRepository<Waitings> waitingsRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="waitingsRepository"></param>
        public WaitingDeleteHandler(IBaseRepository<Waitings> waitingsRepository)
        {
            this.waitingsRepository = waitingsRepository;
        }
        /// <summary>
        /// 业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(WaitingDeleteCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Delete };

            var list= waitingsRepository.GetAll().Where(x=>x.WaitingId==request.WaitingId).FirstOrDefault();
            if (list != null)
            {
                list.IsDel = 1;

                waitingsRepository.Update(list);
            }

            result.Code = (int)CommonErrorCode.Success;
            return result;
        }
    }
}
